﻿#include "collision.h"

PointCollisionBox::PointCollisionBox()
	: CollisionBox(CollisionBoxType::Point), x_(0), y_(0) {}
PointCollisionBox::PointCollisionBox(float x, float y)
	: CollisionBox(CollisionBoxType::Point), x_(std::abs(x)), y_(std::abs(y)) {}


float PointCollisionBox::getX() const { return x_; }
float PointCollisionBox::getY() const { return y_; }

bool PointCollisionBox::setX(float x) {
	if (x >= 0) {
		x_ = x;
		return true;
	}
	return false;
}
bool PointCollisionBox::setY(float y) {
	if (y >= 0) {
		y_ = y;
		return true;
	}
	return false;
}


bool PointCollisionBox::checkCollision(const CollisionBox& other) const {
	return other.checkCollisionWithPoint(*this);
}

bool PointCollisionBox::checkCollisionWithPoint(const PointCollisionBox& point) const {
	
	return (x_ == point.x_) && (y_ == point.y_);
}

bool PointCollisionBox::checkCollisionWithRectangle(const RectangleCollisionBox& rect) const {
	return (x_ >= rect.getX() && x_ <= rect.getX() + rect.getWidth() &&
		y_ >= rect.getY() && y_ <= rect.getY() + rect.getLength());
}

bool PointCollisionBox::checkCollisionWithCircle(const CircleCollisionBox& circle) const {
	float dx = x_ - circle.getX();
	float dy = y_ - circle.getY();
	return (dx * dx + dy * dy) <= (circle.getRadius() * circle.getRadius());
}